import { Component, Input, OnInit } from '@angular/core';
import { FormBuilder, FormGroup } from '@angular/forms';
import { NzModalRef } from 'ng-zorro-antd/modal';

@Component({
  selector: '',
  template: ``,
})
export abstract class RefEntityDetailComponent<T> implements OnInit {
  validateForm: FormGroup;
  @Input() model: T;
  constructor(public fb: FormBuilder, public modalRef: NzModalRef) {}

  abstract ngOnInit(): void;

  cancelForm() {
    this.modalRef.close(null);
  }

  submitForm() {
    if (!this.validateForm.valid) return;

    this.modalRef.close({
      ...this.model,
      ...this.validateForm.value,
      ...this.getEntity(),
    });
  }

  protected getEntity() {
    return {};
  }
}
